
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="extinct/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="extinct/css/commonly-used-show.css" />
    <script type="text/javascript" src="extinct/js/jquery.min.js"></script>
    <script type="text/javascript" src="extinct/js/bootstrap.js" ></script>

    <!--  缓存 -->
    <script type="text/javascript" src="extinct/js/jquery.cookie.js"></script>

    <!--  提示框 -->
    <link rel="stylesheet" type="text/css" href="extinct/css/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="extinct/css/modal.css" />
    <script type="text/javascript" src="extinct/js/modal.js" ></script>

    <!--  分页显示 -->
    <script src="extinct/js/jqPaginator.min.js" type="text/javascript"></script>
    <link href="extinct/css/myPage.css" rel="stylesheet" type="text/css" />
    <script src="extinct/js/myPage.js" type="text/javascript"></script>

    <title>土地管理</title>

    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>



</head>
<body class="mybody">

<jsp:include page="theTopMenuAdmin.jsp" />

<div class="container-fluid">
    <div class="row">


        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">


                            <div style="margin-left: 50px; margin-right: 50px;">
    <h3 style="text-align: center">土地信息列表</h3>
    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>序号</th>
            <th>土地名称</th>
            <th>土地面积</th>
            <th>土地地址</th>
            <th>土地联系人</th>
            <th>耕种状态</th>
            <th>联系方式</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>

        <tbody id="tbody-result">
        </tbody>

    </table>
                            </div>



                            <div class="text-center">


                                <div style="margin-top: 20px;">

                                    <div style="float: left; margin-left: 130px;" class="col-lg-4 ">
                <div class="input-group">
                    <input id="user_find" type="text" class="form-control" placeholder="土地名称或联系人查找">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" onclick="findUse()">查找</button>
                    </span>
                </div>
            </div>

                                    <div style="float: right; margin-right: 100px;">
                                        <a class="btn btn-primary" href="${pageContext.request.contextPath}/addLand?id=1">添加土地</a>
                                    </div>

                                    <div style="clear: both">

                                    </div>

                                </div>

                                <div style="margin-top: 20px;">
                                    <span id="user_messge" style="font-size:10px; color: red;"></span>
                                </div>

                                <div>
                                    <ul class="pagination" id="pagination"></ul>
                                    <!--PageCount是一共多少条数据-->
                                    <input type="hidden" id="PageCount" />
                                    <!--PageSize是页面显示多少条数据-->
                                    <input type="hidden" id="PageSize" value="7"/>
                                    <!--countindex这个参数是通过上面的PageCount与PageSize计算出来的分多少页-->
                                    <!--js中是自动计算的，可默认也可以自己填-->
                                    <input type="hidden" id="countindex" value="10"/>
                                    <!--上一页与下一页中间的数字框，要显示几个就value多少个-->
                                    <input type="hidden" id="visiblePages" value="6"/>
                                </div>

                            </div>



                        </div>
                    </div>
                </div>
        </div>



    </div>

 </div>



<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));

    if (userdt.data.userName != null){
        $("#usname").text(userdt.data.userName);
    }else {
        $("#usname").text(userdt.data.userLoginName);
    }

    //设置全局变量
    var numes = 1;
    var isok = true;


    /*loadData(num,count)写在$(function(){})外，num为当前选中页码，count是我自己加的，是ajax返回的数据总数*/
    function loadData(num, count) {
        numes = num;
        if (count){
            $("#PageCount").val(count);
        }else {
            $("#PageCount").val("5");
        }

        //当点击首页，下一页，上一页，尾页，数字页码时执行ajax数据操作
        if (numes !== 1){
            queryLandInfo();
        }else if (numes === 1){
            queryLandInfo();
        }

    }

    //输入查找的条件时进行查找操作
    function findUse(){
        isok = true;
        queryLandInfo();
    }

    //每当数据发生变动时进行页面的刷新
    function uppag(count){
        //重新加载分页控件
        loadData(1, count);
        loadpage();
        isok = false;
    }

    window.onload = function(){
        queryLandInfo();
    }

    //进行ajax异步请求，完成数据的查询
    function queryLandInfo(){
        var postUrl = "${pageContext.request.contextPath}/member/allLandList";
        var str = {
            "pageResult": {
                "currentPage": numes,
                "pageSize": 7
            },
            "landName": $("#user_find").val(),
            "landContact": $("#user_find").val()
        };
        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(result){
                if (result.code === 502){
                    $("#user_messge").text(result.data);

                    if (result.data === "查询失败,无该数据"){
                        uppag(0);
                        $("#tbody-result").html("");
                    }

                }else {
                    //全局变量，第一次加载后就不执行了，当用户进行查找操作时在继续执行
                    if (isok){
                        uppag(result.data.totalSize);
                    }

                    var strtab = "";
                    //清空表格数据
                    $("#tbody-result").html("");
                    //自定义序号
                    var conter = 1;

                    var myFarmingState;

                    for (var i = 0; i < result.data.items.length; i++) {
                        if (result.data.items[i].landCultivationStatus === "1"){
                            myFarmingState = "未耕种";
                        }else if (result.data.items[i].landCultivationStatus === "2"){
                            myFarmingState = "已耕种";
                        }else if (result.data.items[i].landCultivationStatus === "3"){
                            myFarmingState = "已出租";
                        }else if (result.data.items[i].landCultivationStatus === "4"){
                            myFarmingState = "未知";
                        }

                        //对数据进行拼接，在显示出来
                        strtab = "<tr>" + "<td>" + conter + "</td>"
                            + "<td>" + result.data.items[i].landName + "</td>"
                            + "<td>" + result.data.items[i].landArea + "</td>"
                            + "<td>" + result.data.items[i].landAddress + "</td>"
                            + "<td>" + result.data.items[i].landContact + "</td>"
                            + "<td>" + myFarmingState + "</td>"
                            + "<td>" + result.data.items[i].landContactPhone + "</td>"
                            + "<td>" + result.data.items[i].createTime + "</td>"
                            + "<td>" + "<a class=\"btn btn-default btn-sm\" href=${pageContext.request.contextPath}/addLand?id=" + result.data.items[i].id +  ">" + "修改" + "</a> "
                            + "<a class=\"btn btn-default btn-sm\" href=\"#\" onclick=\"deleteLand('"+ result.data.items[i].id + "')\">删除</a>" + "</td>"
                            + "</tr>";
                        $("#tbody-result").append(strtab);//将数据追加进表格

                        //自定义序号
                        conter++;
                    }

                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }


    //删除一个用户
    function deleteLand(datees){

        //显示提示对话框
        var mModal2 = new mModal({
            top: "40vh",
            content: "你确定要删除此项？",
            confirm: function () {
                deleteLand1(datees);
                mModal2.close();
            },
            cancel: function () {
            }
        });

        mModal2.renderDom();
    }


    function deleteLand1(id){
        var postUrl = "${pageContext.request.contextPath}/member/deleteLand";
        var str = {
            "id": id
        };
        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(result){
                if (result.code === 502){
                    $("#user_messge").text(result.data);
                }else {
                    location.reload();
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>